package com.example.administrator.hqq.adapter.register;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.activity.register.SetMessageActivity;
import com.example.administrator.hqq.adapter.SetOnClickItem;
import com.example.administrator.hqq.bean.MessageBean;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2018/10/30 17:39
 * @remark:
 */
public class MessageHeadAdater extends RecyclerView.Adapter<MessageHeadAdater.ViewHoder>{
    private Context context;
    private List<MessageBean.DataBean> data;
    private SetOnClickItem setOnClickItem;
    public MessageHeadAdater(Context setMessageActivity, List<MessageBean.DataBean> data) {
        this.context= setMessageActivity;
        this.data=data;
    }

    class ViewHoder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        public ViewHoder(View itemView) {
            super(itemView);
            AutoUtils.autoSize(itemView);
            imageView=itemView.findViewById(R.id.add);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (setOnClickItem!=null)
                    {
                        setOnClickItem.setOnClickItem(getPosition());
                    }
                }
            });
        }
    }
    @NonNull
    @Override
    public ViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.head_image_layout, null);
        ViewHoder viewHoder = new ViewHoder(inflate);
        return viewHoder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHoder holder, int position) {
        if (data.get(position).isSelect())
        {
            Glide.with(context).load(data.get(position).getUrl_true()).centerCrop().into(holder.imageView);
        }
        else{
            Glide.with(context).load(data.get(position).getUrl_false()).centerCrop().into(holder.imageView);
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void setSetOnClickItem(SetOnClickItem setOnClickItem) {
        this.setOnClickItem = setOnClickItem;
    }
}
